#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int Maxn=4e5+5;
int n,a[Maxn],b[Maxn];
int f[Maxn];
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
int vis[Maxn],ans;
int main(){
	freopen("pairint.in","r",stdin);
	freopen("pairint.out","w",stdout);
	n=read();
	for(int i=1;i<=2*n;i++)f[i]=i;
	for(int i=1;i<=n;i++){
		a[i]=read();b[i]=read();
		if(!vis[find(a[i])]){
			vis[find(a[i])]=1;ans++;
			f[find(a[i])]=find(b[i]);
		}else if(!vis[find(b[i])]){
			vis[find(b[i])]=1;ans++;
			f[find(b[i])]=find(a[i]);
		}
	}
	printf("%d\n",ans);
	return 0;
}

